﻿function isNull()
{
    var userName  = document.getElementById("TextBoxEmployeeNo").value;
    var userPwd  = document.getElementById("TextBoxPassword").value;
    if(userName ==  "") 
    {
        window.alert ('Account field should not be blank.');
        return false ;
    }
    if(userPwd == "")
    {
        window.alert ('Password field should not be blank.');
        return false ;
    }
}

function isUserNull()
{
    var userName  = document.getElementById("TextBoxEmployeeNo").value;
    if(userName.length == 0)
    {
        window.alert('Account field should not be blank.');
         return false;
    }
    else
    {
      var IsCancel;
      IsCancel = window.confirm ('Do you want to reset your password？');
      if(IsCancel)
      {
        return true ;
      }
      else
      {
        window.history.back(-1);  
        return false ;       
      }
    }
}

function InputTextBox(obj) {
   var text=obj.value;
   if ((text.indexOf("'")>-1)||(text.indexOf("<")>-1)||(text.indexOf(">")>-1))
    {
        alert("Invalid Input.")
        obj.value="";
        obj.focus();
        return false;
    }
} 

function clearDefaultText(){
    //获得事件对象
    if(window.event)oEvent = window.event;
    //从时间对象中获得引起时间的
    var oText = event.srcElement;  
    //改变对象的属性
    oText.style.color = "black";
    oText.value = "";
    //取消事件
    oText.onclick = null;
}


function clearDefaultTextByKeydown() {
    //获得事件对象
    
    if (window.event) oEvent = window.event;
    //从时间对象中获得引起时间的
    var oText = event.srcElement;
    //alert(oText.value == "Your email account")
    //alert(oText.style.color)
    if ((oText.value == "Your account") && (oText.style.color == "gray")) {
        //改变对象的属性
        //alert('1')
        oText.style.color = "black";
        oText.value = "";
        //取消事件

        oText.onclick = null;
    }
    else
    {
        if ((oText.value.indexOf("'")>-1)||(oText.value.indexOf("<")>-1)||(oText.value.indexOf(">")>-1))
        {
            alert("Invalid Input.")
            oText.style.color = "black";
            oText.value = "";
            oText.onclick = null;
        }
    }
}

function defaultText(){
    //获得事件对象
    if(window.event)oEvent = window.event;
    //从时间对象中获得引起时间的
    var oText = event.srcElement;
    var text = oText.value;   
    if(text.replace(/(^\s*)|(\s*$)/g,'')=='')
    {
        oText.style.color = "Gray";
        oText.value = "Your account";
        oText.onclick = clearDefaultText;
    }
}


window.onload=function(){

    //获得标签名为input的元素
    var oTextBox = document.getElementsByTagName("input");
    //遍历
    for(var i=0;i<oTextBox.length;i++){
        //如果是text
        if(oTextBox[i].type == "text")
        {
            if(oTextBox[i].value != "Your account"){
                oTextBox[i].style.color = "black";
            }else
            {
                oTextBox[i].style.color = "Gray";
                oTextBox[i].onclick = clearDefaultText;
            }
            oTextBox[i].onblur = defaultText;           
        }
    }
}